#include "buildingtooltip.h"

BuildingToolTip::BuildingToolTip(QGraphicsScene *scene)
    : QGraphicsRectItem(0,0,105,50,0,scene)
{
    setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    setVisible(false);
    setZValue(3);

    tipText = new QGraphicsTextItem(this,scene);
    tipText->setPos(1,13);
    tipText->setFont(QFont("SansSerif",9,QFont::Bold));
    tipText->setAcceptHoverEvents(false);
    

    healthBar = new HealthBar(this,scene);
    healthBar->setPos(5,5);
}

void BuildingToolTip::updateToolTip(qreal health, int people, int infected)
{
    healthBar->setHealth(health);

    QString convertString;

    QString toolTipText = "Occupants: ";
    toolTipText.append(convertString.setNum(people));
    toolTipText.append("\n   Infected: ");
    toolTipText.append(convertString.setNum(infected));

    //tipText->setPlainText(toolTipText);
}

void BuildingToolTip::moveToolTip(QPointF mousePos)
{
        setPos(mousePos.x(),mousePos.y()-rect().height());
}

HealthBar::HealthBar(QGraphicsItem *parent, QGraphicsScene *scene)
    : QGraphicsRectItem(0,0,97,8, parent, scene)
{
    setAcceptHoverEvents(false);
    setAcceptedMouseButtons(false);
}

void HealthBar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->fillRect(0,0,healthyPixles,8,QColor(Qt::darkGreen));
    painter->fillRect(healthyPixles,0,infectedPixles,8,QColor(Qt::red));
}

void HealthBar::setHealth(qreal health)
{
    healthyPixles = (97*health);
    infectedPixles = (97-healthyPixles);
}
